<template>
  <div class="ele-body">
    <a-card :bordered="false">
      <!-- 搜索表单 -->
      <a-form :label-col="{ md: { span: 6 }, sm: { span: 24 } }" :wrapper-col="{ md: { span: 18 }, sm: { span: 24 } }">
        <a-row>
          <a-col :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-item label="车队">
              <a-auto-complete v-model:value="driverWhere.carTeam" :options="carTeamOptions" placeholder="请输入车队"
                @select="carTeam_se_onSelect" @search="carTeam_onSearch" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-item label="车牌号">
              <a-input v-model:value.trim="driverWhere.carNo" placeholder="请输入车牌号" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-item label="司机姓名">
              <a-input v-model:value.trim="driverWhere.name" placeholder="请输入司机姓名" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" :xs="24">
            <a-form-item label="司机手机">
              <a-input v-model:value.trim="driverWhere.phone" placeholder="请输入司机手机" allow-clear />
            </a-form-item>
          </a-col>
          <a-col :lg="6" :md="12" :sm="24" :xs="24" >
            <a-form-item :wrapper-col="{ span: 24 }">
              <em></em>
              <a-space>
                <a-button type="primary" @click="driverReload">查询</a-button>
                <a-button @click="driverReset">重置</a-button>
              </a-space>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
      <!-- 表格 -->
      <ele-pro-table ref="driverTableRef" row-key="id" :columns="columns" 
      :datasource="datasource" 
      v-model:current="driverCurrent"
        @update:selection="driverTableOnSelectionChange"  :customRow="driverTableRowClick" 
      :scroll="{ x: 1000 }">
        <template #toolbar>
          <a-space>
            <a-button type="primary" @click="driverOpenEdit()" v-any-permission="['order:driver:save']">
              <template #icon>
                <plus-outlined />
              </template>
              <span>新建</span>
            </a-button>
            <a-button v-if="driverCurrent.id > 0" type="primary" @click="exportDriver()">
              <template #icon>
                <plus-outlined />
              </template>
              <span>拖车账单</span>
            </a-button>
          </a-space>
        </template>
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'action'">
            <a-space>
              <a @click="driverOpenEdit(record)" v-any-permission="['order:driver:update']">修改</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定要删除此项吗？" @confirm="driverRemove(record)">
                <a class="ele-text-danger" v-any-permission="['order:driver:remove']">删除</a>
              </a-popconfirm>
            </a-space>
          </template>
        </template>
      </ele-pro-table>
    </a-card>
    <!-- 司机管理添加、修改弹窗 -->
    <ele-modal :width="460" v-model:visible="driverVisible_modal" :confirm-loading="driverLoading" :title="driverIsUpdate ? '修改司机管理' : '新建司机管理'"
      :body-style="{ paddingBottom: '8px' }" @ok="driverSave" :maskClosable="false">
      <a-form ref="driverFormRef" :model="{...driverForm, oneFormValidate:oneFormValidate}" :rules="driverRules" :label-col="{ md: { span: 7 }, sm: { span: 24 } }"
        :wrapper-col="{ md: { span: 17 }, sm: { span: 24 } }">
        <!-- <a-form-item label="车队" :name="['oneFormValidate',0,'price']" :rules="{required: true,message: '请填写售价',trigger: 'blur', type: 'number'}">
          <a-input-number
                v-model:value="oneFormValidate[0].price"
                :min="0"
                :max="9999999999"
                :precision="2"
                allow-clear
                placeholder="请填写售价"
                style="width: 100%"
              />
        </a-form-item> -->
        <a-form-item label="车队" name="carTeam_val">
          <a-auto-complete v-model:value="driverForm.carTeam_val" :options="carTeamOptions" placeholder="请输入车队"
          @select="carTeam_onSelect" @search="carTeam_onSearch" @blur="carTeam_blur" allow-clear />
        </a-form-item>
        <a-form-item label="账号" name="account">
          <a-input allow-clear :maxlength="50" placeholder="请输入账号" v-model:value="driverForm.account" autocomplete="off" :disabled="driverIsUpdate"/>
        </a-form-item>
        <a-form-item label="姓名" name="name">
          <a-input allow-clear :maxlength="200" placeholder="请输入姓名" v-model:value="driverForm.name" autocomplete="off" />
        </a-form-item>
        <!-- <a-form-item label="身份证图片" name="idCardPic">
          <a-input allow-clear :maxlength="200" placeholder="请输入身份证图片" v-model:value="driverForm.idCardPic" autocomplete="off" />
        </a-form-item> -->
        <a-form-item label="电话" name="phone">
          <a-input allow-clear :maxlength="200" placeholder="请输入电话" v-model:value="driverForm.phone" autocomplete="off" />
        </a-form-item>
        <a-form-item label="车牌" name="carNo">
          <a-input allow-clear :maxlength="200" placeholder="请输入车牌" v-model:value="driverForm.carNo" autocomplete="off" />
        </a-form-item>
        <a-form-item label="身份证" name="idCard">
          <a-input allow-clear :maxlength="200" placeholder="请输入身份证" v-model:value="driverForm.idCard" autocomplete="off" />
        </a-form-item>
        <a-form-item label="白卡号文字" name="whiteCard">
          <a-input allow-clear :maxlength="200" placeholder="请输入白卡号文字" v-model:value="driverForm.whiteCard" autocomplete="off" />
        </a-form-item>
        <!-- <a-form-item label="白卡号图片" name="whiteCardPic">
          <a-input allow-clear :maxlength="200" placeholder="请输入白卡号图片" v-model:value="driverForm.whiteCardPic" autocomplete="off" />
        </a-form-item>
        <a-form-item label="白卡号结束日期" name="whiteCardDate">
          <a-input allow-clear :maxlength="200" placeholder="请输入白卡号结束日期" v-model:value="driverForm.whiteCardDate" autocomplete="off" />
        </a-form-item>
        <a-form-item label="白卡号开始日期" name="whiteCardDateStart">
          <a-input allow-clear :maxlength="200" placeholder="请输入白卡号开始日期" v-model:value="driverForm.whiteCardDateStart" autocomplete="off" />
        </a-form-item> -->
        <!-- <a-form-item label="行驶证以及对应图片" name="vehicleLicense">
          <a-input allow-clear :maxlength="200" placeholder="请输入行驶证以及对应图片" v-model:value="driverForm.vehicleLicense" autocomplete="off" />
        </a-form-item>
        <a-form-item label="行驶证结束日期" name="vehicleLicenseDate">
          <a-input allow-clear :maxlength="200" placeholder="请输入行驶证结束日期" v-model:value="driverForm.vehicleLicenseDate" autocomplete="off" />
        </a-form-item>
        <a-form-item label="行驶证开始日期" name="vehicleLicenseDateStart">
          <a-input allow-clear :maxlength="200" placeholder="请输入行驶证开始日期" v-model:value="driverForm.vehicleLicenseDateStart" autocomplete="off" />
        </a-form-item>
        <a-form-item label="驾驶证以及对应图片" name="driveLicense">
          <a-input allow-clear :maxlength="200" placeholder="请输入驾驶证以及对应图片" v-model:value="driverForm.driveLicense" autocomplete="off" />
        </a-form-item>
        <a-form-item label="驾驶证结束日期" name="driveLicenseDate">
          <a-input allow-clear :maxlength="200" placeholder="请输入驾驶证结束日期" v-model:value="driverForm.driveLicenseDate" autocomplete="off" />
        </a-form-item>
        <a-form-item label="驾驶证开始日期" name="driveLicenseDateStart">
          <a-input allow-clear :maxlength="200" placeholder="请输入驾驶证开始日期" v-model:value="driverForm.driveLicenseDateStart" autocomplete="off" />
        </a-form-item>
        <a-form-item label="挂靠公司营业执照以及对应图片" name="corporationLicensePic">
          <a-input allow-clear :maxlength="200" placeholder="请输入挂靠公司营业执照以及对应图片" v-model:value="driverForm.corporationLicensePic" autocomplete="off" />
        </a-form-item>
        <a-form-item label="车辆营运证图片" name="operationLicense">
          <a-input allow-clear :maxlength="200" placeholder="请输入车辆营运证图片" v-model:value="driverForm.operationLicense" autocomplete="off" />
        </a-form-item>
        <a-form-item label="车辆营运证结束日期" name="operationLicenseDate">
          <a-input allow-clear :maxlength="200" placeholder="请输入车辆营运证结束日期" v-model:value="driverForm.operationLicenseDate" autocomplete="off" />
        </a-form-item>
        <a-form-item label="车辆营运证开始日期" name="operationLicenseDateStart">
          <a-input allow-clear :maxlength="200" placeholder="请输入车辆营运证开始日期" v-model:value="driverForm.operationLicenseDateStart" autocomplete="off" />
        </a-form-item>
        <a-form-item label="保险图片" name="insuranceLicense">
          <a-input allow-clear :maxlength="200" placeholder="请输入保险图片" v-model:value="driverForm.insuranceLicense" autocomplete="off" />
        </a-form-item>
        <a-form-item label="保险结束日期" name="insuranceLicenseDate">
          <a-input allow-clear :maxlength="200" placeholder="请输入保险结束日期" v-model:value="driverForm.insuranceLicenseDate" autocomplete="off" />
        </a-form-item>
        <a-form-item label="保险开始日期" name="insuranceLicenseDateStart">
          <a-input allow-clear :maxlength="200" placeholder="请输入保险开始日期" v-model:value="driverForm.insuranceLicenseDateStart" autocomplete="off" />
        </a-form-item>
        <a-form-item label="司机从业资格证图片" name="qualificationCertificate">
          <a-input allow-clear :maxlength="200" placeholder="请输入司机从业资格证图片" v-model:value="driverForm.qualificationCertificate" autocomplete="off" />
        </a-form-item> -->
        <!-- <a-form-item label="银行名称" name="bankName">
          <a-input allow-clear :maxlength="200" placeholder="请输入银行名称" v-model:value="driverForm.bankName" autocomplete="off" />
        </a-form-item>
        <a-form-item label="银行卡卡号" name="bankNo">
          <a-input allow-clear :maxlength="200" placeholder="请输入银行卡卡号" v-model:value="driverForm.bankNo" autocomplete="off" />
        </a-form-item>
        <a-form-item label="紧急联系人号码" name="urgentPhone">
          <a-input allow-clear :maxlength="200" placeholder="请输入紧急联系人号码" v-model:value="driverForm.urgentPhone" autocomplete="off" />
        </a-form-item>
        <a-form-item label="审核状态: 已审核,未审核,审核未通过" name="state">
          <a-input allow-clear :maxlength="200" placeholder="请输入审核状态: 已审核,未审核,审核未通过" v-model:value="driverForm.state" autocomplete="off" />
        </a-form-item> -->
        <!-- <a-form-item label="类型A类B类" name="type">
          <a-input allow-clear :maxlength="200" placeholder="请输入类型A类B类" v-model:value="driverForm.type" autocomplete="off" />
        </a-form-item> -->
      </a-form>
    </ele-modal>
    <!-- 司机费用导出弹窗 -->
    <ele-modal :width="460" v-model:visible="driverExportVisible" :confirm-loading="driverLoading" :title="'司机费用导出'"
      position="center" :body-style="{ paddingBottom: '8px' }" @ok="driverExportSave" :maskClosable="false">
      <a-form :label-col="{ md: { span: 7 }, sm: { span: 24 } }" :wrapper-col="{ md: { span: 17 }, sm: { span: 24 } }">
        <a-form-item label="司机" name="">
          {{ driverCurrent.name }}
        </a-form-item>
        <a-form-item label="日期" name="factoryPackDate2">
          <a-range-picker v-model:value="factoryPackDate2" :format="YYYY - MM - DD" placeholder="" class="ele-fluid" :allow-clear="false"/>
        </a-form-item>
      </a-form>
    </ele-modal>
  </div>
</template>

<script setup>
import { ref, reactive,watch } from 'vue';
import { toDateString } from 'ele-admin-pro';
import useFormData from '@/utils/use-form-data';
import { message } from 'ant-design-vue';
import { API_BASE_URL, TOKEN_HEADER_NAME } from '@/config/setting';
import { TIME_OUT } from '@/config/damon';
import { getToken } from '@/utils/token-util';
import dayjs from 'dayjs';

import { pageDriver, removeDriver, addDriver, updateDriver } from '@/api/order/driver';

import { listCustomersSel } from '@/api/order/customer';
const oneFormValidate = reactive([
  {
    pic: [],
    price: 0,
    cost: 0,
    ot_price: 0,
    stock: 0,
    bar_code: "",
    weight: 0,
    volume: 0,
    brokerage: 0,
    brokerage_two: 0,
    vip_price: 0,
    virtual_list: [],
    coupon_id: 0
  }
]);
// 表格实例
const driverTableRef = ref(null);

// 表格列配置
const columns = ref([
  {
    key: 'index',
    width: 48,
    align: 'center',
    fixed: 'left',
    hideInSetting: true,
    customRender: ({ index }) => index + (driverTableRef.value?.tableIndex ?? 0)
  },
  {
    title: '车队',
    dataIndex: 'carTeam',
    key: 'carTeam',
    // sorter: true,
  },
  {
    title: '姓名',
    dataIndex: 'name',
    key: 'name',
    // sorter: true,
  },
  // {
  //   title: '身份证图片',
  //   dataIndex: 'idCardPic',
  //   key: 'idCardPic',
  //   // sorter: true,
  // },
  {
    title: '电话',
    dataIndex: 'phone',
    key: 'phone',
    // sorter: true,
  },
  {
    title: '身份证',
    dataIndex: 'idCard',
    key: 'idCard',
    // sorter: true,
  },
  {
    title: '车牌',
    dataIndex: 'carNo',
    key: 'carNo',
    // sorter: true,
  },
  {
    title: '白卡号文字',
    dataIndex: 'whiteCard',
    key: 'whiteCard',
    // sorter: true,
  },
  // {
  //   title: '白卡号图片',
  //   dataIndex: 'whiteCardPic',
  //   key: 'whiteCardPic',
  //   // sorter: true,
  // },
  // {
  //   title: '白卡号结束日期',
  //   dataIndex: 'whiteCardDate',
  //   key: 'whiteCardDate',
  //   // sorter: true,
  // },
  // {
  //   title: '白卡号开始日期',
  //   dataIndex: 'whiteCardDateStart',
  //   key: 'whiteCardDateStart',
  //   // sorter: true,
  // },
  // {
  //   title: '行驶证以及对应图片',
  //   dataIndex: 'vehicleLicense',
  //   key: 'vehicleLicense',
  //   // sorter: true,
  // },
  // {
  //   title: '行驶证结束日期',
  //   dataIndex: 'vehicleLicenseDate',
  //   key: 'vehicleLicenseDate',
  //   // sorter: true,
  // },
  // {
  //   title: '行驶证开始日期',
  //   dataIndex: 'vehicleLicenseDateStart',
  //   key: 'vehicleLicenseDateStart',
  //   // sorter: true,
  // },
  // {
  //   title: '驾驶证以及对应图片',
  //   dataIndex: 'driveLicense',
  //   key: 'driveLicense',
  //   // sorter: true,
  // },
  // {
  //   title: '驾驶证结束日期',
  //   dataIndex: 'driveLicenseDate',
  //   key: 'driveLicenseDate',
  //   // sorter: true,
  // },
  // {
  //   title: '驾驶证开始日期',
  //   dataIndex: 'driveLicenseDateStart',
  //   key: 'driveLicenseDateStart',
  //   // sorter: true,
  // },
  // {
  //   title: '挂靠公司营业执照以及对应图片',
  //   dataIndex: 'corporationLicensePic',
  //   key: 'corporationLicensePic',
  //   // sorter: true,
  // },
  // {
  //   title: '车辆营运证图片',
  //   dataIndex: 'operationLicense',
  //   key: 'operationLicense',
  //   // sorter: true,
  // },
  // {
  //   title: '车辆营运证结束日期',
  //   dataIndex: 'operationLicenseDate',
  //   key: 'operationLicenseDate',
  //   // sorter: true,
  // },
  // {
  //   title: '车辆营运证开始日期',
  //   dataIndex: 'operationLicenseDateStart',
  //   key: 'operationLicenseDateStart',
  //   // sorter: true,
  // },
  // {
  //   title: '保险图片',
  //   dataIndex: 'insuranceLicense',
  //   key: 'insuranceLicense',
  //   // sorter: true,
  // },
  // {
  //   title: '保险结束日期',
  //   dataIndex: 'insuranceLicenseDate',
  //   key: 'insuranceLicenseDate',
  //   // sorter: true,
  // },
  // {
  //   title: '保险开始日期',
  //   dataIndex: 'insuranceLicenseDateStart',
  //   key: 'insuranceLicenseDateStart',
  //   // sorter: true,
  // },
  // {
  //   title: '司机从业资格证图片',
  //   dataIndex: 'qualificationCertificate',
  //   key: 'qualificationCertificate',
  //   // sorter: true,
  // },
  // {
  //   title: '银行名称',
  //   dataIndex: 'bankName',
  //   key: 'bankName',
  //   // sorter: true,
  // },
  // {
  //   title: '银行卡卡号',
  //   dataIndex: 'bankNo',
  //   key: 'bankNo',
  //   // sorter: true,
  // },
  // {
  //   title: '紧急联系人号码',
  //   dataIndex: 'urgentPhone',
  //   key: 'urgentPhone',
  //   // sorter: true,
  // },
  // {
  //   title: '审核',
  //   dataIndex: 'state',
  //   key: 'state',
  //   // sorter: true,
  // },
  // {
  //   title: '类型A类B类',
  //   dataIndex: 'type',
  //   key: 'type',
  //   // sorter: true,
  // },
  // {
  //   title: '排序',
  //   dataIndex: 'orderNum',
  //   key: 'orderNum',
  //   // sorter: true,
  // },
  {
    title: '账号',
    dataIndex: 'account',
    key: 'account',
    // sorter: true,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    // sorter: true,
    resizable: true,
    width: 150,
    ellipsis: true,
    customRender: ({ text }) => toDateString(text)
  },
  {
    title: '创建人',
    dataIndex: 'createName',
    key: 'createName',
    // sorter: true,
  },
  {
    title: '更新时间',
    dataIndex: 'updateTime',
    key: 'updateTime',
    // sorter: true,
    resizable: true,
    width: 150,
    ellipsis: true,
    customRender: ({ text }) => toDateString(text)
  },
  {
    title: '更新人',
    dataIndex: 'updateName',
    key: 'updateName',
    // sorter: true,
  },
  {
    title: '操作',
    key: 'action',
    width: 200,
    align: 'center',
    fixed: 'right',
    hideInSetting: true
  }
]);

// 表单数据
const { form: driverWhere, resetFields } = useFormData({
  username: '',
  sex: undefined
});

// 表格数据源
const datasource = ({ page, limit, where, orders }) => {
  return pageDriver({ ...where, ...orders, page, limit });
};

/* 搜索 */
const driverReload = () => {
  driverTableRef?.value?.reload({ page: 1, where: driverWhere });
};
const driverReload2 = () => {
  driverTableRef?.value?.reload();
};

let where_timeout = 0
watch(() => driverWhere, (val) => {
  clearTimeout(where_timeout)
  where_timeout = setTimeout(() => {
    driverReload()
  }, TIME_OUT);
},
{ deep: true }
)

/*  重置 */
const driverReset = () => {
  resetFields();
  driverReload();
};

/* 删除单个 */
const driverRemove = (record) => {
  const hide = message.loading('请求中..', 0);
  removeDriver(record.id).then((msg) => {
    hide();
    message.success(msg);
    driverReload2();
  }).catch((e) => {
    hide();
    message.error(e.message);
  });
};

// 当前选中数据
const driverCurrent = ref({id: 0});

// 弹窗是否打开
const driverVisible_modal = ref(false);

// 弹窗是否打开
const driverExportVisible = ref(false);
// 是否是修改
const driverIsUpdate = ref(false);

// 提交状态
const driverLoading = ref(false);

//
const driverFormRef = ref(null);

// 表单数据
const { form: driverForm, resetFields: driverResetFormFields } = useFormData({
  id: undefined,
  customer: '',
  vessel: '',
});

// 表单验证规则
const driverRules = reactive({
  carTeam_val: [
    {
      required: true,
      message: '请输入车队',
      type: 'string',
    }
  ],
  name: [
    {
      required: true,
      message: '请输入姓名',
      type: 'string',
    }
  ],
  phone: [
    {
      required: true,
      message: '请输入电话',
      type: 'string',
    }
  ],
  carNo: [
    {
      required: true,
      message: '请输入车牌',
      type: 'string',
    }
  ],
});


//excel导出
function exportDriver() {
  driverExportVisible.value = true
}
let factoryPackDate2 = ref([
  dayjs().startOf('month'),
  dayjs().endOf('month'),
  // dayjs().add(2, 'month'),
])

function getDate_self(op) {
  let monght_s = op.getMonth() + 1
  let day_s = op.getDate()
  if (monght_s < 10) { monght_s = '0' + monght_s }
  if (day_s < 10) { day_s = '0' + day_s }
  return op.getFullYear() + '-' + monght_s + '-' + day_s
}
/* 客户费用导出 */
const driverExportSave = () => {
  if (factoryPackDate2.value == null) {
    factoryPackDate2.value = []
  }
  if (factoryPackDate2.value.length > 0) {
    let date1 = getDate_self(new Date(factoryPackDate2.value[0]))
    let date2 = getDate_self(new Date(factoryPackDate2.value[1]))
    let dataStr = '?date1=' + date1 + '&date2=' + date2 + '&driver=' + driverCurrent.value.name 
    + '&driverId=' + driverCurrent.value.id + '&type=应付'
    let url = API_BASE_URL + '/order/driver/exportsDriver' + dataStr
    // window.open(API_BASE_URL + '/order/driver/exportsDriver' + dataStr, '_blank');
    // window.location.href = API_BASE_URL + '/order/driver/exportsDriver' + dataStr;
    var xhr = new XMLHttpRequest();
    xhr.open("get", url, true); // get、post都可
    xhr.responseType = "blob";  // 转换流                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
    xhr.setRequestHeader(TOKEN_HEADER_NAME, getToken()); // token键值对
    xhr.onload = function () {
      if (this.status == 200) {
        var blob = this.response;
        var a = document.createElement("a")
        var url = window.URL.createObjectURL(blob)
        a.href = url
        a.download = driverCurrent.value.name + " 账期：" + date1 + "到" + date2 + ".xlsx"  // 文件名
      }
      a.click()
      window.URL.revokeObjectURL(url)
    }
    xhr.send();
    message.success('导出成功');
  driverExportVisible.value = false
  } else {
  }
};

let driverTableRowClick = (record, index) => {
  return {
    onClick: (event) => {
      driverCurrent.value = record;
    },
  }
}
let driverTableOnSelectionChange = (current_options) => {
  driverCurrent.value = current_options[0];
};
const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  },
  getCheckboxProps: record => ({
    disabled: record.name === 'Disabled User',
    // Column configuration not to be checked
    name: record.name,
  }),
};
//防止重复刷新
const carTeamOptions = ref([]);
let carTeam_m_timeout = 0
const carTeam_onSearch = searchText => {
  clearTimeout(carTeam_m_timeout)
  carTeam_m_timeout = setTimeout(() => {
    listCustomersSel({ 'name': searchText, type: '车队' }).then(msg => {
      carTeamOptions.value = msg
    }).catch((e) => {
    })
  }, TIME_OUT);
};
const carTeam_onSelect = (value2, option2) => {
  // let a = carTeamOptions.value.find((item)=> {return item.value=value})
  driverForm.carTeam_val = option2.label
  driverForm.carTeam = option2.label
  driverForm.carTeamId = option2.value
};
const carTeam_se_onSelect = (value2, option2) => {
  driverWhere.carTeam = option2.label
};
const carTeam_m_change = (value2) => {
  // let a = carTeamOptions.value.find((item)=> {return item.value=value2})
  // driverForm.carTeam_val=a.label
  // driverForm.carTeam=a.label
};
const carTeam_blur = () => {
  driverForm.carTeam_val = driverForm.carTeam
};

/* 打开编辑弹窗 */
const driverOpenEdit = (record) => {
  driverResetFormFields();
  driverFormRef.value?.clearValidate();
  driverCurrent.value = record?? {};
  driverVisible_modal.value = true;
  Object.assign(driverForm, record ?? {});
  if (record == undefined) {
    driverForm.carTeam_val = ''
  } else {
    driverForm.carTeam_val = record.carTeam
  }
  driverIsUpdate.value = !!record;
};

/* 保存编辑 */
const driverSave = () => {
  if (!driverFormRef.value) {
    return;
  }
  driverFormRef.value.validate().then(() => {
    driverLoading.value = true;
    const saveOrUpdate = driverIsUpdate.value ? updateDriver : addDriver;
    saveOrUpdate(driverForm).then((msg) => {
      driverLoading.value = false;
      message.success(msg);
      driverVisible_modal.value = false;
      driverReload2();
    }).catch((e) => {
      driverLoading.value = false;
      message.error(e.message);
    });
  }).catch(() => {
  });
};
</script>

<script>
export default {
  name: 'DemoTest'
};
</script>

